import store from "@/store"
const install = (Vue, vm) => {
	// 此为自定义配置参数，具体参数见上方说明
	Vue.prototype.$u.http.setConfig({
		baseUrl: 'https://api-hmugo-web.itheima.net/api/public/v1',
		loadingText: '努力加载中~',
		loadingTime: 100
	});
    //请求拦截器
    Vue.prototype.$u.http.interceptor.request = (config) => {
		//只有请求里包含/my/才会被拦截并加上token
		if (config.url.includes("/my/")) {
			config.header.Authorization = store.state.user.token;
		  }
		  return config;		
	}

    Vue.prototype.$u.http.interceptor.response = (res) => {
	   if(res.meta && res.meta.status === 200){
           return res.message
       }else{
           return res.meta
       }
	}
}

export default {
	install
}